package modellayer;

import java.util.ArrayList;

public class OrderContainer {
	private static OrderContainer instance;
	private ArrayList<Order> orders;

	private OrderContainer() {
		orders = new ArrayList<Order>();
	}
	
	public static OrderContainer getInstance()
	{
		if(instance == null)
		{
			instance = new OrderContainer();
		}
		return instance;
	}
	public ArrayList<Order> getOrders() {
		return orders;
	}
	
	public void addOrder(Order o){
		orders.add(o);
	}
	
	public Order findOrder(int orderID){
        Order returnOrder = null;
        boolean found = false;
        int size = orders.size();
        for(int i = 0;  i < size && !found;i++)
        {
            if(orders.get(i).getOrderID() == (orderID))
            {
            	returnOrder = orders.get(i);
                found = true;
            }
        }
        return returnOrder;
    }
	public void removeOrder(int orderID){
		Order tempO = findOrder(orderID);
		orders.remove(tempO);
	}

	public void updateOrder(int oldOrderID, int newOrderID, double price, Salesman salesman, Customer customer, String date){
		Order tempO = findOrder(oldOrderID);
		tempO.setOrderID(newOrderID);
		tempO.setPrice(price);
		tempO.setSalesman(salesman);
		tempO.setCustomer(customer);
		tempO.setDate(date);

	}
}
